package xyz.yq56.kafka_demo.mq;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
public class Product {

    @Resource
    private KafkaTemplate<String,String> kafkaTemplate;

    @Scheduled(cron = "0/20 * * * * ? ")
    public void send(){
        System.out.println("已进入SEND");
        for (int i = 0; i < 10; i++) {
            String topic = "sun";
            kafkaTemplate.send(new ProducerRecord<>(topic,"第"+i+"条message"));
        }
    }
}